$(function () {
  jQuery('.focusBox').hover(
    function () {
      jQuery(this).find('.prev,.next').stop(true, true).fadeTo('show', 0.2)
    },
    function () {
      jQuery(this).find('.prev,.next').fadeOut()
    },
  )
  //大图切换
  jQuery('.sharedSquareInfo').slide({ titCell: '.smallImg li', mainCell: '.bigImg', effect: 'fold', autoPlay: true, delayTime: 200 }) //小图左滚动切换
  jQuery('.sharedSquareInfo .smallScroll').slide({ mainCell: 'ul', delayTime: 100, vis: 5, effect: 'left', pnLoop: false, autoPage: true, prevCell: '.sPrev', nextCell: '.sNext' })
  jQuery('.focusBox').slide({
    mainCell: '.pic',
    effect: 'fold',
    autoPlay: true,
    delayTime: 600,
    trigger: 'click',
  })

  jQuery('#nav').slide({
    type: 'menu', //效果类型
    titCell: '.mainCate', // 鼠标触发对象
    targetCell: '.subCate', // 效果对象，必须被titCell包含
    delayTime: 0, // 效果时间
    triggerTime: 0, //鼠标延迟触发时间
    defaultPlay: false, //默认执行
    returnDefault: true, //返回默认
  })
  jQuery('.picScroll1').slide({
    mainCell: 'ul',
    effect: 'leftLoop',
    vis: 5,
    scroll: 1,
    autoPage: true,
    pnLoop: false,
    // autoPlay: true,
    switchLoad: '_src',
  })
  var day = document.getElementById('day')
  var hours = document.getElementById('hours')
  var minutes = document.getElementById('minutes')
  var seconds = document.getElementById('seconds')
  // 获取当前日期
  const today = new Date()

  // 设置为明天
  today.setDate(today.getDate() + 1)

  // 获取明天的年月日时分秒
  const tomorrowYear = today.getFullYear()
  const tomorrowMonth = ('0' + (today.getMonth() + 1)).slice(-2) // 月份是从0开始的
  const tomorrowDay = ('0' + today.getDate()).slice(-2)
  const tomorrowHours = '20'
  const tomorrowMinutes = '00'
  const tomorrowSeconds = '00'
  const tomorrowFormatted = `${tomorrowYear}/${tomorrowMonth}/${tomorrowDay} ` + `${tomorrowHours}:${tomorrowMinutes}:${tomorrowSeconds}`
  // 日 时 分 秒的dom对象
  countDownTime.init(tomorrowFormatted, day, hours, minutes, seconds)
  countDownTime.start()
  $('#city').click(function (e) {
    SelCity(this, e)
  })
  $('.search-select dd').click(function (e) {
    $('.search-select .t').html($(this).text())
  })

  jQuery('.sharedSquareInfo .details_list li .details_list_right .specification').click(function () {
    $(this).addClass('active').siblings().removeClass('active')
  })
  jQuery('.num_input .minus').click(function () {
    var t = parseInt(jQuery(this).next('input').val())
    if (isNaN(t)) return
    t <= 1 ||
      jQuery(this)
        .next('input')
        .val(t - 1)
        .trigger('input')
  })
  jQuery('.num_input .plus').click(function () {
    var t = parseInt(jQuery(this).prev('input').val())
    if (isNaN(t)) return
    jQuery(this)
      .prev('input')
      .val(t + 1)
      .trigger('input')
  })

  $('select').on('change', function () {
    $('select').each((i, element) => {
      if (!$(element).val()) {
        $(element).css('color', '#999')
      } else {
        $(element).css('color', '#666')
      }
    })
  })

  jQuery('.endTime').flatpickr({ minDate: new Date(), defaultDate: new Date(), })
  jQuery('.startTime').flatpickr({
    defaultDate: new Date(),
    onChange: function (selectedDates) {
      $('.endTime')
        .flatpickr({
          minDate: selectedDates,
        })
        .redraw()
    },
  })
})
